<form style="padding:20px;" class="layui-form  seller-alone-form operationForm">
    <input type="hidden" value="{$info.id}" name="id" />
    <div class="layui-form-item">
        <label class="layui-form-label"><i class="required-color">*</i>父节点：</label>
        <div class="layui-input-inline">
            <select name="parent_id" id="parent_id" lay-filter="parent_id" lay-verify="required" lay-search="" >
                <!--<option value="1">根节点</option>-->
                <option value="">直接选择或搜索选择</option>
                {volist name='tree' id='vo'}
                    <option value="{$vo.id}" {if $info.parent_id == $vo.id} selected=""{/if}> |— {$vo.name}({$vo.code})</option>
                    {volist name='vo["children"]' id='vi'}
                        <option value="{$vi.id}" {if $info.parent_id == $vi.id} selected=""{/if}> |—|— {$vi.name}({$vi.code})</option>
                        {volist name='vi["children"]' id='vj'}
                            <option value="{$vj.id}" {if $info.parent_id == $vj.id} selected=""{/if}> |—|—|— {$vj.name}({$vj.code})</option>
                        {/volist}
                    {/volist}
                {/volist}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><i class="required-color">*</i>名称：</label>
        <div class="layui-input-inline">
            <input type="text" name="name"  placeholder="请输入名称" value="{$info.name}" autocomplete="off" class="layui-input" lay-verify="required">
        </div>
        <div class="layui-form-mid layui-word-aux">请输入操作的名称</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><i class="required-color">*</i>编码：</label>
        <div class="layui-input-inline">
            <input type="text" name="code" id="code" placeholder="请输入编码" value="{$info.code}" autocomplete="off" class="layui-input" lay-verify="required">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><i class="required-color">*</i>菜单节点：</label>
        <div class="layui-input-inline">
            <select name="parent_menu_id" id="parent_menu_id" lay-filter="parent_menu_id" lay-search="" lay-verify="required">
                <!--<option value="1">根节点</option>-->
                <option value="">直接选择或搜索选择</option>
                {volist name='menuTree' id='vo'}
                    <?php if($vo['isEditLast'] === 0): ?>
                        <option value="{$vo.id}" {if $info.parent_menu_id == $vo.id} selected=""{/if}> |— {$vo.name}({$vo.code})</option>
                        {volist name='vo["children"]' id='vi'}
                            <?php if($vi['isEditLast'] === 0): ?>
                                <option value="{$vi.id}" {if $info.parent_menu_id == $vi.id} selected=""{/if}> |—|— {$vi.name}({$vi.code})</option>
                                {volist name='vi["children"]' id='vj'}
                                    <?php if($vj['isEditLast'] === 0): ?>
                                    <option value="{$vj.id}" {if $info.parent_menu_id == $vj.id} selected=""{/if}> |—|—|— {$vj.name}({$vj.code})</option>
                                        {volist name='vj["children"]' id='vk'}
                                            <?php if($vk['isEditLast'] === 0): ?>
                                                <option value="{$vk.id}" {if $info.parent_menu_id == $vk.id} selected=""{/if}> |—|—|—|— {$vk.name}({$vk.code})</option>
                                            <?php endif ?>
                                        {/volist}
                                    <?php endif ?>
                                {/volist}
                            <?php endif ?> 
                        {/volist}
                    <?php endif ?>
                {/volist}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><i class="required-color">*</i>类型：</label>
        <div class="layui-input-block">
            <!--<input type="radio" name="type" value="m" title="模块" {if $info.type == 'm'} checked=""{/if}>-->
            <input type="radio" name="type" id="typeC" value="c" title="控制器" {if $info.type == 'c'} checked=""{/if}>
            <input type="radio" name="type" id="typeM" value="a" title="方法"  {if !isset($info) || $info.type == 'a'} checked=""{/if} >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><i class="required-color">*</i>权限许可：</label>
        <div class="layui-input-block">
            <input type="radio" name="perm_type" value="1" title="主体权限-在菜单上和权限设置上都显示" {if !isset($info) || $info.perm_type == '1'} checked=""{/if}><br />
            <input type="radio" name="perm_type" value="2" title="半主体权限-只在权限设置上显示" {if $info.perm_type == '2'} checked=""{/if}><br />
            <input type="radio" name="perm_type" value="3" title="关联权限-权限依附于所属的菜单节点" {if $info.perm_type == '3'} checked=""{/if}>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><i class="required-color">*</i>叶子节点：</label>
        <div class="layui-input-block">
            <input type="radio" name="isEditLast" id="typeC" value="1" title="是" {if !isset($info) || $info.isEditLast == '1'} checked=""{/if}>
            <input type="radio" name="isEditLast" id="typeM" value="0" title="否"  {if $info.isEditLast == '0'} checked=""{/if} >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><i class="required-color">*</i>排序：</label>
        <div class="layui-input-block">
            {php}
            if($info){
            $sort = $info['sort'];
            }else{
            $sort = 100;
            }
            {/php}
            <input type="text" name="sort" required style="width:60px;"  lay-verify="required" value="{$sort}" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">注意：</label>
    
        <div class="layui-input-block" style="font-size:14px; padding:5px">
            <p>1.父节点必须和控制器命名空间路径一致，菜单节点可以根据使用逻辑自行组织。</p>
            <p>2.控制器，如果在菜单上（控制器只能在一级菜单上）显示，就设置为主体权限，否则就设置成关联权限即可，而菜单节点一定要写成和父节点一样即可。</p>
            <p>3.如果是控制器，code按照正常的大小写写法即可，如果是方法，一定要是小写。</p>
            <p>4.所有通过路径访问的方法必须增加菜单节点否则非Admin账户无法授权使用。</p>
        </div>
    </div> 
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="hidden" name="open_spec" value="0">
            {:zlserverToken()}
            <button id="operation_edit_save" class="layui-btn" lay-submit="" lay-filter="save">保存</button>
        </div>
    </div>
    {:zlserverToken()}
</form> 
<script src="../layui/layui.js"></script>
<script>
    layui.use(['form', 'laydate'], function () {
        var form = layui.form;
        form.render();
  
        //保存用户
        form.on('submit(save)', function(data){
            var thedata = $('.operationForm').serialize();
            var parent_id = $("#parent_id").val();
            if (parent_id == '' || !parent_id) {
                layer.msg("请选择父节点");
                return false;
            }

            var parent_menu_id = $("#parent_menu_id").val();
            if (parent_menu_id == '' || !parent_menu_id) {
                layer.msg("请选择菜单节点");
                return false;
            }
 
            var typeGroup = $("[name='type']").filter(":checked");
            if(typeGroup.attr("id") === "typeC"){
                var code = $("#code").val();
                var reg = /^[a-zA-Z]+$/;
                if (!reg.test(code)) {
                    layer.msg("【编码】只能输入字母");
                    return false;
                }
            } else {
                var code = $("#code").val();
                var reg = /^[a-z]+$/;
                if (!reg.test(code)) {
                    layer.msg("【编码】只能输入小写字母");
                    return false;
                }
            }

            $("#operation_edit_save").addClass("layui-btn-disabled");
            $('#operation_edit_save').attr("disabled", true);
            
            $.ajax({
                type: 'post',
                url: '{:url("Operation/edit")}',
                data: thedata,
                dataType: 'json',
                success: function (e) { 
                    if(e.status === true){ 
                        layer.open({
                            type: 1
                            ,offset: 'auto'
                            ,id: 'layerDemoAuto'
                            ,content: '<div style="padding: 20px 100px;">'+ e.msg +'</div>'
                            ,btn: '关闭'
                            ,btnAlign: 'c' //按钮居中
                            ,shade: 0.3 //显示遮罩
                            ,yes: function(){
                                parent.layui.admin.events.changeTabAndRefresh('/manage/operation/index.html', 'operationTable');
                            },close: function() {
                                console.log('close');
                            },end: function () {
                                parent.layui.admin.events.changeTabAndRefresh('/manage/operation/index.html', 'operationTable');
                            }
                        });
                    }else{
                        $("#operation_edit_save").removeClass("layui-btn-disabled");
                        $('#operation_edit_save').removeAttr("disabled");

                        layer.msg(e.msg, {time: 1300});
                    }
                }
            });
            return false;
        });
    });
</script>
